<!Doctype html>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
	<meta name="viewport" content="width=device-width, initial-scale=1.0" />
	<title>Java 基本数据类型 | 菜鸟教程</title>

  <meta name='robots' content='max-image-preview:large' />
<link rel='stylesheet' id='classic-theme-styles-css' href='../0/classic-themes.min.css?ver=6.2' type='text/css' media='all' />
<link rel="canonical" href="../java/java-basic-datatypes.html" />
<meta name="keywords" content="Java 基本数据类型">
<meta name="description" content="Java 基本数据类型 变量就是申请内存来存储值。也就是说，当创建变量的时候，需要在内存中申请空间。 内存管理系统根据变量的类型为变量分配存储空间，分配的空间只能用来储存该类型数据。   因此，通过定义不同类型的变量，可以在内存中储存整数、小数或者字符。 Java 的两大数据类型: 内置数据类型 引用数据类型  内置数据类型 Java语言提供了八种基本类型。六种数字类型（四个整数型，两个浮点型），一种字符类型，还有一种布尔型。  byt..">
		
	<link rel="shortcut icon" href="https://static.runoob.com/images/favicon.ico">
	<link rel="stylesheet" href="../0/style.css?v=1.170" type="text/css" media="all" />	
	<link rel="stylesheet" href="../0/font-awesome.min.css" media="all" />	
  <!--[if gte IE 9]><!-->
  <script src=""></script>
  <!--<![endif]-->
  <!--[if lt IE 9]>
     <script src=""></script>
     <script src=""></script>
  <![endif]-->
  <link rel="apple-touch-icon" href="https://static.runoob.com/images/icon/mobile-icon.png"/>
  <meta name="apple-mobile-web-app-title" content="菜鸟教程">
</head>
<body>

<!--  头部 -->
<div class="container logo-search">

  <div class="col search row-search-mobile">
    <form action="index.php">
      <input class="placeholder" placeholder="搜索……" name="s" autocomplete="off">
      
    </form>
  </div>

  <div class="row">
    <div class="col logo">
      <h1><a href="../">菜鸟教程 -- 学的不仅是技术，更是梦想！</a></h1>
    </div>
        <div class="col right-list"> 
    <button class="btn btn-responsive-nav btn-inverse" data-toggle="collapse" data-target=".nav-main-collapse" id="pull" style=""> <i class="fa fa-navicon"></i> </button>
    </div>
        
    <div class="col search search-desktop last">
      <div class="search-input" >
      <form action="//www.runoob.com/" target="_blank">
        <input class="placeholder" id="s" name="s" placeholder="搜索……"  autocomplete="off" style="height: 44px;">
      </form>
      
      </div>
    </div>
  </div>
</div>



<!-- 导航栏 -->
<!-- 导航栏 -->
<div class="container navigation">
	<div class="row">
		<div class="col nav">
			<ul class="pc-nav" id="runoob-detail-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JavaScript</a></li>
				<li><a href="javascript:void(0);" data-id="vue">Vue</a></li>
				<li><a href="javascript:void(0);" data-id="bootstrap">Bootstrap</a></li>
				<li><a href="../nodejs/nodejs-tutorial.html">NodeJS</a></li>
				<li><a href="../python3/python3-tutorial.html">Python3</a></li>
				<li><a href="../python/python-tutorial.html">Python2</a></li>
				<li><a href="../java/java-tutorial.html">Java</a></li>
				<li><a href="../cprogramming/c-tutorial.html">C</a></li>
				<li><a href="../cplusplus/cpp-tutorial.html">C++</a></li>
				<li><a href="../csharp/csharp-tutorial.html">C#</a></li>
				<li><a href="../go/go-tutorial.html">Go</a></li>
				<li><a href="../sql/sql-tutorial.html">SQL</a></li>
				<li><a href="../linux/linux-tutorial.html">Linux</a></li>
				<li><a href="../jquery/jquery-tutorial.html">jQuery</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<!--
			
				<li><a href="../w3cnote/knowledge-start.html" style="font-weight: bold;" onclick="_hmt.push(['_trackEvent', '星球', 'click', 'start'])" title="我的圈子">我的圈子</a></li>				
				<li><a href="javascript:;" class="runoob-pop">登录</a></li>
				-->
      		</ul>
			<ul class="mobile-nav">
				<li><a href="../">首页</a></li>
				<li><a href="../html/html-tutorial.html">HTML</a></li>
				<li><a href="../css/css-tutorial.html">CSS</a></li>
				<li><a href="../js/js-tutorial.html">JS</a></li>
				<li><a href="../browser-history">本地书签</a></li>
				<li><a href="javascript:void(0)" class="search-reveal">Search</a> </li>
			</ul>
			
		</div>
	</div>
</div>

<div class="container sub-navigation sub-navigation-articles" style="display:none">
	<div class="row">
		<div class="col nav-sub">
		<ul id="python">
			<li class="cat-item"><a href="../python3/python3-tutorial.html">Python3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../python/python-tutorial.html">Python2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		<ul id="vue">
			<li class="cat-item"><a href="../vue3/vue3-tutorial.html">Vue3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../vue/vue-tutorial.html">vue2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>

		<ul id="bootstrap">
			<li class="cat-item"><a href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
			<li class="cat-item"><a href="../bootstrap/bootstrap-v2-tutorial.html">Bootstrap2 教程 <i class="fa fa-external-link" aria-hidden="true"></i></a></li>
		</ul>
		</div>
	</div>
</div><!--  内容  -->
<div class="container main">
	<!-- 中间 -->
	<div class="row">
	
<div class="runoob-col-md2">
<div class="left-column">
	<div class="tab" style="overflow: hidden;text-overflow: ellipsis;white-space: nowrap;">
	<i class="fa fa-list" aria-hidden="true"></i> 
	<span>Java 教程</span>
	<a data-cate="53" href="javascript:void(0);" title="夜间模式"  id="moon"><i class="fa fa-moon-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;"></i></a>
	<a data-cate="53" style="display:none;" href="javascript:void(0);" title="日间模式"  id="sun" ><i class="fa fa-sun-o" aria-hidden="true" style="line-height: 28px;font-size: 1.2em;margin: 2px 4px 0;line-height: 28px;
}"></i></a>

	</div>
	<div class="sidebar-box gallery-list">
		<div class="design" id="leftcolumn">
						<a target="_top" title="Java 教程"  href="../java/java-tutorial.html" >
			Java 教程			</a>
						<a target="_top" title="Java 简介"  href="../java/java-intro.html" >
			Java 简介			</a>
						<a target="_top" title="Java 开发环境配置"  href="../java/java-environment-setup.html" >
			Java 开发环境配置			</a>
						<a target="_top" title="Java 基础语法"  href="../java/java-basic-syntax.html" >
			Java 基础语法			</a>
						<a target="_top" title="Java 对象和类"  href="../java/java-object-classes.html" >
			Java 对象和类			</a>
						<a target="_top" title="Java 基本数据类型"  href="../java/java-basic-datatypes.html" >
			Java 基本数据类型			</a>
						<a target="_top" title="Java 变量类型"  href="../java/java-variable-types.html" >
			Java 变量类型			</a>
						<a target="_top" title="Java 修饰符"  href="../java/java-modifier-types.html" >
			Java 修饰符			</a>
						<a target="_top" title="Java 运算符"  href="../java/java-operators.html" >
			Java 运算符			</a>
						<a target="_top" title="Java 循环结构 &#8211; for, while 及 do&#8230;while"  href="../java/java-loop.html" >
			Java 循环结构			</a>
						<a target="_top" title="Java 条件语句 &#8211; if&#8230;else"  href="../java/java-if-else-switch.html" >
			Java 条件语句			</a>
			<a target="_top" title="Java switch case 语句" href="../java/java-switch-case.html">Java switch case</a>			<a target="_top" title="Java Number &#038; Math 类"  href="../java/java-number.html" >
			Java Number & Math 类			</a>
						<a target="_top" title="Java Character 类"  href="../java/java-character.html" >
			Java Character 类			</a>
						<a target="_top" title="Java String 类"  href="../java/java-string.html" >
			Java String 类			</a>
						<a target="_top" title="Java StringBuffer 和 StringBuilder 类"  href="../java/java-stringbuffer.html" >
			Java StringBuffer			</a>
						<a target="_top" title="Java 数组"  href="../java/java-array.html" >
			Java 数组			</a>
						<a target="_top" title="Java 日期时间"  href="../java/java-date-time.html" >
			Java 日期时间			</a>
						<a target="_top" title="Java 正则表达式"  href="../java/java-regular-expressions.html" >
			Java 正则表达式			</a>
						<a target="_top" title="Java 方法"  href="../java/java-methods.html" >
			Java 方法			</a>
						<a target="_top" title="Java 流(Stream)、文件(File)和IO"  href="../java/java-files-io.html" >
			Java Stream、File、IO			</a>
			<a target="_top" title="Java Scanner 类" href="java-scanner-class.html"> Java Scanner 类 </a>			<a target="_top" title="Java 异常处理"  href="../java/java-exceptions.html" >
			Java 异常处理			</a>
			<br><h2 class="left">Java <span class="left_h2">面向对象</span></h2>			<a target="_top" title="Java 继承"  href="../java/java-inheritance.html" >
			Java 继承			</a>
						<a target="_top" title="Java 重写(Override)与重载(Overload)"  href="../java/java-override-overload.html" >
			Java Override/Overload			</a>
						<a target="_top" title="Java 多态"  href="../java/java-polymorphism.html" >
			Java 多态			</a>
						<a target="_top" title="Java 抽象类"  href="../java/java-abstraction.html" >
			Java 抽象类			</a>
						<a target="_top" title="Java 封装"  href="../java/java-encapsulation.html" >
			Java 封装			</a>
						<a target="_top" title="Java 接口"  href="../java/java-interfaces.html" >
			Java 接口			</a>
			<a target="_top" title="Java 枚举" href="../java/java-enum.html">
			Java 枚举			</a>			<a target="_top" title="Java 包(package)"  href="../java/java-package.html" >
			Java 包(package)			</a>
			<br><h2 class="left">Java <span class="left_h2">高级教程</span></h2>			<a target="_top" title="Java 数据结构"  href="../java/java-data-structures.html" >
			Java 数据结构			</a>
						<a target="_top" title="Java 集合框架"  href="../java/java-collections.html" >
			Java 集合框架			</a>
			<a target="_top" title="Java ArrayList" href="../java/java-arraylist.html">Java ArrayList</a>
<a target="_top" title="Java LinkedList" href="../java/java-linkedlist.html">Java LinkedList</a>
<a target="_top" title="Java HashSet" href="../java/java-hashset.html">Java HashSet</a>
<a target="_top" title="Java  HashMap" href="../java/java-hashmap.html">Java  HashMap</a>
<a target="_top" title="Java  Iterator" href="../java/java-iterator.html">Java  Iterator</a>
<a target="_top" title="Java  Object" href="../java/java-object-class.html">Java  Object</a>			<a target="_top" title="Java 泛型"  href="../java/java-generics.html" >
			Java 泛型			</a>
						<a target="_top" title="Java 序列化"  href="../java/java-serialization.html" >
			Java 序列化			</a>
						<a target="_top" title="Java 网络编程"  href="../java/java-networking.html" >
			Java 网络编程			</a>
						<a target="_top" title="Java 发送邮件"  href="../java/java-sending-email.html" >
			Java 发送邮件			</a>
						<a target="_top" title="Java 多线程编程"  href="../java/java-multithreading.html" >
			Java 多线程编程			</a>
						<a target="_top" title="Java Applet 基础"  href="../java/java-applet-basics.html" >
			Java Applet 基础			</a>
						<a target="_top" title="Java 文档注释"  href="../java/java-documentation.html" >
			Java 文档注释			</a>
						<a target="_top" title="Java 实例"  href="../java/java-examples.html" >
			Java 实例			</a>
						<a target="_top" title="Java 8  新特性"  href="../java/java8-new-features.html" >
			Java 8  新特性			</a>
						<a target="_top" title="Java MySQL 连接"  href="../java/java-mysql-connect.html" >
			Java MySQL 连接			</a>
						<a target="_top" title="Java 9 新特性"  href="../java/java9-new-features.html" >
			Java 9 新特性			</a>
			<a target="_blank" title="Java 测验" href="../quiz/java-quiz.html">Java 测验</a>	
		</div>
	</div>	
</div>
</div>	<div class="col middle-column">
		
	
	<div class="article">
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../java/java-object-classes.html" rel="prev"> Java 对象和类</a> </div>
			<div class="next-design-link"><a href="../java/java-variable-types.html" rel="next"> Java 变量类型</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
<div class="article-heading-ad" style="display: block;">
<script async src=""
     crossorigin="anonymous"></script>
<!-- 728*90 固定 -->
<ins class="adsbygoogle"
     style="display:inline-block;width:728px;height:90px"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="2147566827"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
		<div class="article-body">
		
			<div class="article-intro" id="content">
			
			<h1>Java 基本数据类型</h1>
<p>变量就是申请内存来存储值。也就是说，当创建变量的时候，需要在内存中申请空间。</p>
<p>内存管理系统根据变量的类型为变量分配存储空间，分配的空间只能用来储存该类型数据。</p>
<p>
<img decoding="async" src="https://www.runoob.com/wp-content/uploads/2013/12/2020-10-27-code-mem.png"></p>
<p>因此，通过定义不同类型的变量，可以在内存中储存整数、小数或者字符。</p>
<p>Java 的两大数据类型:</p>
<ul><li>内置数据类型</li>
<li>引用数据类型</li>
</ul><hr>
<h2>内置数据类型</h2>
<p>Java语言提供了八种基本类型。六种数字类型（四个整数型，两个浮点型），一种字符类型，还有一种布尔型。 </p>
<p><strong>byte：</strong></p>
<ul>
	<li>
		byte 数据类型是8位、有符号的，以二进制补码表示的整数；</li>
	<li>
		最小值是 <span class="marked">-128（-2^7）</span>；</li>
	<li>
		最大值是 <span class="marked">127（2^7-1）</span>；</li>
	<li>
		默认值是 <span class="marked">0</span>；</li>
	<li>
		byte 类型用在大型数组中节约空间，主要代替整数，因为 byte 变量占用的空间只有 int 类型的四分之一；</li>
	<li>
		例子：byte a = 100，byte b = -50。</li>
</ul>
<p><strong>short：</strong></p>
<ul>
	<li>
		short 数据类型是 16 位、有符号的以二进制补码表示的整数</li>
	<li>
		最小值是 <span class="marked">-32768（-2^15）</span>；</li>
	<li>
		最大值是 <span class="marked">32767（2^15 - 1）</span>；</li>
	<li>
		Short 数据类型也可以像 byte 那样节省空间。一个short变量是int型变量所占空间的二分之一；</li>
	<li>
		默认值是 <span class="marked">0</span>；</li>
	<li>
		例子：short s = 1000，short r = -20000。</li>
</ul>
<p><strong>int：</strong></p>
<ul>
	<li>
		int 数据类型是32位、有符号的以二进制补码表示的整数；</li>
	<li>
		最小值是 <span class="marked">-2,147,483,648（-2^31）</span>；</li>
	<li>
		最大值是 <span class="marked">2,147,483,647（2^31 - 1）</span>；</li>
	<li>
		一般地整型变量默认为 int 类型；</li>
	<li>
		默认值是 <span class="marked">0</span> ；</li>
	<li>
		例子：int a = 100000, int b = -200000。</li>
</ul>
<p><strong>long：</strong></p>
<ul>
	<li>
		long 数据类型是 64 位、有符号的以二进制补码表示的整数；</li>
	<li>
		最小值是 <span class="marked">-9,223,372,036,854,775,808（-2^63）</span>；</li>
	<li>
		最大值是 <span class="marked">9,223,372,036,854,775,807（2^63 -1）</span>；</li>
	<li>
		这种类型主要使用在需要比较大整数的系统上；</li>
	<li>
		默认值是 <span class="marked">0L</span>；</li>
	<li>
		例子： <span class="marked">long a = 100000L</span>，<span class="marked">long b = -200000L</span>。<br>
"L"理论上不分大小写，但是若写成"l"容易与数字"1"混淆，不容易分辩。所以最好大写。
</li>
</ul>
<p><strong>float：</strong></p>
<ul>
	<li>
		float 数据类型是单精度、32位、符合IEEE 754标准的浮点数；</li>
	<li>
		float 在储存大型浮点数组的时候可节省内存空间；</li>
	<li>
		默认值是 <span class="marked">0.0f</span>；</li>
	<li>
		浮点数不能用来表示精确的值，如货币；</li>
	<li>
		例子：float f1 = 234.5f。</li>
</ul>
<p><strong>double：</strong></p>
<ul>
	<li>
		double 数据类型是双精度、64 位、符合 IEEE 754 标准的浮点数；</li>
	<li>
		浮点数的默认类型为 double 类型；</li>
	<li>
		double类型同样不能表示精确的值，如货币；</li>
	<li>
		默认值是 <span class="marked">0.0d</span>；</li>
	<li>
		<p>例子：</p>

<pre>double   d1  = 7D ;
double   d2  = 7.; 
double   d3  =  8.0; 
double   d4  =  8.D; 
double   d5  =  12.9867; </pre>
<p>7 是一个 int 字面量，而 7D，7. 和 8.0 是 double 字面量。</p>
</li>
</ul>
<p><strong>boolean：</strong></p>
<ul>
	<li>
		boolean数据类型表示一位的信息；</li>
	<li>
		只有两个取值：true 和 false；</li>
	<li>
		这种类型只作为一种标志来记录 true/false 情况；</li>
	<li>
		默认值是 <span class="marked">false</span>；</li>
	<li>
		例子：boolean one = true。</li>
</ul>
<p><strong>char：</strong></p>
<ul>
	<li>
		char 类型是一个单一的 16 位 Unicode 字符；</li>
	<li>
		最小值是 <span class="marked">\u0000</span>（十进制等效值为 0）；</li>
	<li>
		最大值是 <span class="marked">\uffff</span>（即为 65535）；</li>
	<li>
		char 数据类型可以储存任何字符；</li>
	<li>
		例子：char letter = 'A';。</li>
</ul>
<h3>实例</h3>
<p>对于数值类型的基本类型的取值范围，我们无需强制去记忆，因为它们的值都已经以常量的形式定义在对应的包装类中了。请看下面的例子：</p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">PrimitiveTypeTest</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">  
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">  
        </span><span class="hl-comment">//</span><span class="hl-comment"> byte  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：byte 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Byte</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Byte</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Byte.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Byte</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Byte.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Byte</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
  
        </span><span class="hl-comment">//</span><span class="hl-comment"> short  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：short 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Short</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Short</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Short.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Short</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Short.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Short</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
  
        </span><span class="hl-comment">//</span><span class="hl-comment"> int  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：int 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Integer</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Integer</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Integer.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Integer</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Integer.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Integer</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
  
        </span><span class="hl-comment">//</span><span class="hl-comment"> long  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：long 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Long</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Long</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Long.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Long</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Long.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Long</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
  
        </span><span class="hl-comment">//</span><span class="hl-comment"> float  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：float 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Float</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Float</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Float.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Float</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Float.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Float</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
  
        </span><span class="hl-comment">//</span><span class="hl-comment"> double  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：double 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Double</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Double</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Double.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Double</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Double.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Double</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-brackets">)</span><span class="hl-code">;  
  
        </span><span class="hl-comment">//</span><span class="hl-comment"> char  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">基本类型：char 二进制位数：</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">Character</span><span class="hl-code">.</span><span class="hl-identifier">SIZE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">包装类：java.lang.Character</span><span class="hl-quotes">&quot;</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-comment">//</span><span class="hl-comment"> 以数值形式而不是字符形式将Character.MIN_VALUE输出到控制台  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最小值：Character.MIN_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code">  
                + </span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-identifier">Character</span><span class="hl-code">.</span><span class="hl-identifier">MIN_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
        </span><span class="hl-comment">//</span><span class="hl-comment"> 以数值形式而不是字符形式将Character.MAX_VALUE输出到控制台  </span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">最大值：Character.MAX_VALUE=</span><span class="hl-quotes">&quot;</span><span class="hl-code">  
                + </span><span class="hl-brackets">(</span><span class="hl-types">int</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-identifier">Character</span><span class="hl-code">.</span><span class="hl-identifier">MAX_VALUE</span><span class="hl-brackets">)</span><span class="hl-code">;  
    </span><span class="hl-brackets">}</span><span class="hl-code">  
</span><span class="hl-brackets">}</span></div>
</div>
<br>
<a target="_blank" href="../try/showjava.php?filename=PrimitiveTypeTest" class="showbtn" rel="noopener noreferrer">运行实例 »</a>
</div>
<p>编译以上代码输出结果如下所示：</p>
<pre>
基本类型：byte 二进制位数：8
包装类：java.lang.Byte
最小值：Byte.MIN_VALUE=-128
最大值：Byte.MAX_VALUE=127

基本类型：short 二进制位数：16
包装类：java.lang.Short
最小值：Short.MIN_VALUE=-32768
最大值：Short.MAX_VALUE=32767

基本类型：int 二进制位数：32
包装类：java.lang.Integer
最小值：Integer.MIN_VALUE=-2147483648
最大值：Integer.MAX_VALUE=2147483647

基本类型：long 二进制位数：64
包装类：java.lang.Long
最小值：Long.MIN_VALUE=-9223372036854775808
最大值：Long.MAX_VALUE=9223372036854775807

基本类型：float 二进制位数：32
包装类：java.lang.Float
最小值：Float.MIN_VALUE=1.4E-45
最大值：Float.MAX_VALUE=3.4028235E38

基本类型：double 二进制位数：64
包装类：java.lang.Double
最小值：Double.MIN_VALUE=4.9E-324
最大值：Double.MAX_VALUE=1.7976931348623157E308

基本类型：char 二进制位数：16
包装类：java.lang.Character
最小值：Character.MIN_VALUE=0
最大值：Character.MAX_VALUE=65535
</pre>
<p>Float和Double的最小值和最大值都是以科学记数法的形式输出的，结尾的"E+数字"表示E之前的数字要乘以10的多少次方。比如3.14E3就是3.14 × 10<sup>3</sup> =3140，3.14E-3 就是 3.14 x 10<sup>-3</sup> =0.00314。</p>
<p>实际上，JAVA中还存在另外一种基本类型 void，它也有对应的包装类 java.lang.Void，不过我们无法直接对它们进行操作。</p>
<h3>类型默认值</h3><p>
下表列出了 Java 各个类型的默认值：</p>
<table class="reference">
<tbody>
<tr>
<th align="left"><strong>数据类型</strong></th>
<th align="left"><strong>默认值</strong></th>
</tr>
<tr>
<td headers="h1">byte</td>
<td headers="h2">0</td>
</tr>
<tr>
<td headers="h1">short</td>
<td headers="h2">0</td>
</tr>
<tr>
<td headers="h1">int</td>
<td headers="h2">0</td>
</tr>
<tr>
<td headers="h1">long</td>
<td headers="h2">0L</td>
</tr>
<tr>
<td headers="h1">float</td>
<td headers="h2">0.0f</td>
</tr>
<tr>
<td headers="h1">double</td>
<td headers="h2">0.0d</td>
</tr>
<tr>
<td headers="h1">char</td>
<td headers="h2">'u0000'</td>
</tr>
<tr>
<td headers="h1">String (or any object)</td>
<td headers="h2">null</td>
</tr>
<tr>
<td headers="h1">boolean</td>
<td headers="h2">false</td>
</tr>
</tbody>
</table>
<div class="example"><h2 class="example">实例</h2> <div class="example_code"><div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">Test</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">boolean</span><span class="hl-code"> </span><span class="hl-identifier">bool</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">byte</span><span class="hl-code"> </span><span class="hl-identifier">by</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">ch</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">double</span><span class="hl-code"> </span><span class="hl-identifier">d</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">float</span><span class="hl-code"> </span><span class="hl-identifier">f</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">i</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">long</span><span class="hl-code"> </span><span class="hl-identifier">l</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">short</span><span class="hl-code"> </span><span class="hl-identifier">sh</span><span class="hl-code">;
    </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-identifier">String</span><span class="hl-code"> </span><span class="hl-identifier">str</span><span class="hl-code">;
 
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-code"> </span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Bool :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">bool</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Byte :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">by</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Character:</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">ch</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Double :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">d</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Float :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">f</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Integer :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">i</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Long :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">l</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">Short :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">sh</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">String :</span><span class="hl-quotes">&quot;</span><span class="hl-code"> + </span><span class="hl-identifier">str</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div></div></div>
<p>实例输出结果为：</p>
<pre>Bool     :false
Byte     :0
Character:
Double   :0.0
Float    :0.0
Integer  :0
Long     :0
Short    :0
String   :null</pre>
<hr>
<h2>
	引用类型</h2>
<ul>
	<li>
		在Java中，引用类型的变量非常类似于C/C++的指针。引用类型指向一个对象，指向对象的变量是引用变量。这些变量在声明时被指定为一个特定的类型，比如 Employee、Puppy 等。变量一旦声明后，类型就不能被改变了。</li>
	<li>
		对象、数组都是引用数据类型。</li>
	<li>
		所有引用类型的默认值都是null。</li>
	<li>
		一个引用变量可以用来引用任何与之兼容的类型。</li>
	<li>
		例子：Site site = new Site("Runoob")。</li>
</ul>
<hr>
<h2>Java 常量</h2>
<p>常量在程序运行时是不能被修改的。</p>
<p>在 Java 中使用 final 关键字来修饰常量，声明方式和变量类似：</p>
<pre>
final double PI = 3.1415927;
</pre>
<p>
虽然常量名也可以用小写，但为了便于识别，通常使用大写字母表示常量。
</p>

<p>字面量可以赋给任何内置类型的变量。例如：</p>
<pre>
byte a = 68;
char a = 'A'
</pre>
<p>byte、int、long、和short都可以用十进制、16进制以及8进制的方式来表示。</p>
<p>当使用字面量的时候，前缀 <span class="marked">0</span> 表示 8 进制，而前缀 <span class="marked">0x</span> 代表 16 进制, 例如：</p>
<pre>
int decimal = 100;
int octal = 0144;
int hexa =  0x64;
</pre>
<p>和其他语言一样，Java的字符串常量也是包含在两个引号之间的字符序列。下面是字符串型字面量的例子：</p>
<pre>
"Hello World"
"two\nlines"
"\"This is in quotes\""
</pre>
<p>字符串常量和字符变量都可以包含任何 Unicode 字符。例如：</p>
<pre>
char a = '\u0001';
String a = "\u0001";
</pre>
<p>
Java语言支持一些特殊的转义字符序列。</p>
<table class="reference">
	<tbody>
		<tr>
			<th>
				符号</th>
			<th>
				字符含义</th>
		</tr>
		<tr>
			<td>
				\n</td>
			<td>
				换行 (0x0a)</td>
		</tr>
		<tr>
			<td>
				\r</td>
			<td>
				回车 (0x0d)</td>
		</tr>
		<tr>
			<td>
				\f</td>
			<td>
				换页符(0x0c)</td>
		</tr>
		<tr>
			<td>
				\b</td>
			<td>
				退格 (0x08)</td>
		</tr>
		<tr>
			<td>
				\0</td>
			<td>
				空字符 (0x0)</td>
		</tr>
<tr>
			<td>
				\s</td>
			<td>
				空格 (0x20)</td>
		</tr>
		<tr>
			<td>
				\t</td>
			<td>
				制表符</td>
		</tr>
		<tr>
			<td>
				\&quot;</td>
			<td>
				双引号</td>
		</tr>
		<tr>
			<td>
				\&#39;</td>
			<td>
				单引号</td>
		</tr>
		<tr>
			<td>
				\\</td>
			<td>
				反斜杠</td>
		</tr>
		<tr>
			<td>
				\ddd</td>
			<td>
				八进制字符 (ddd)</td>
		</tr>
		<tr>
			<td>
				\uxxxx</td>
			<td>
				16进制Unicode字符 (xxxx)</td>
		</tr>
	</tbody>
</table>
<hr>
<h2>自动类型转换</h2>
<p><b>整型、实型（常量）、字符型数据可以混合运算。运算中，不同类型的数据先转化为同一类型，然后进行运算。</b></p>
<p>转换从低级到高级。</p>
<pre>
低  ------------------------------------&gt;  高

byte,short,char&mdash;&gt; int &mdash;&gt; long&mdash;&gt; float &mdash;&gt; double 
</pre>
<p>数据类型转换必须满足如下规则：</p>
<ul>
<li><p>1. 不能对boolean类型进行类型转换。</p> </li><li>
<p>2. 不能把对象类型转换成不相关类的对象。</p>  </li><li> 
<p>3. 在把容量大的类型转换为容量小的类型时必须使用强制类型转换。</p>   </li><li>
<p>4. 转换过程中可能导致溢出或损失精度，例如：</p> 
<pre>
int i =128;   
byte b = (byte)i;
</pre>
<p>因为 byte 类型是 8 位，最大值为127，所以当 int 强制转换为 byte 类型时，值 128 时候就会导致溢出。</p>
</li>
<li>
<p>5. 浮点数到整数的转换是通过舍弃小数得到，而不是四舍五入，例如：  </p>
<pre>
(int)23.7 == 23;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
(int)-45.89f == -45
</pre>
</li>
</ul>
<h3>自动类型转换</h3>
<p>必须满足转换前的数据类型的位数要低于转换后的数据类型，例如: short数据类型的位数为16位，就可以自动转换位数为32的int类型，同样float数据类型的位数为32，可以自动转换为64位的double类型。
</p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">ZiDongLeiZhuan</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
            </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">c1</span><span class="hl-code">=</span><span class="hl-quotes">'</span><span class="hl-string">a</span><span class="hl-quotes">'</span><span class="hl-code">;</span><span class="hl-comment">//</span><span class="hl-comment">定义一个char类型</span><span class="hl-comment"></span><span class="hl-code">
            </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">i1</span><span class="hl-code"> = </span><span class="hl-identifier">c1</span><span class="hl-code">;</span><span class="hl-comment">//</span><span class="hl-comment">char自动类型转换为int</span><span class="hl-comment"></span><span class="hl-code">
            </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">char自动类型转换为int后的值等于</span><span class="hl-quotes">&quot;</span><span class="hl-code">+</span><span class="hl-identifier">i1</span><span class="hl-brackets">)</span><span class="hl-code">;
            </span><span class="hl-types">char</span><span class="hl-code"> </span><span class="hl-identifier">c2</span><span class="hl-code"> = </span><span class="hl-quotes">'</span><span class="hl-string">A</span><span class="hl-quotes">'</span><span class="hl-code">;</span><span class="hl-comment">//</span><span class="hl-comment">定义一个char类型</span><span class="hl-comment"></span><span class="hl-code">
            </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">i2</span><span class="hl-code"> = </span><span class="hl-identifier">c2</span><span class="hl-code">+</span><span class="hl-number">1</span><span class="hl-code">;</span><span class="hl-comment">//</span><span class="hl-comment">char 类型和 int 类型计算</span><span class="hl-comment"></span><span class="hl-code">
            </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">char类型和int计算后的值等于</span><span class="hl-quotes">&quot;</span><span class="hl-code">+</span><span class="hl-identifier">i2</span><span class="hl-brackets">)</span><span class="hl-code">;
        </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>运行结果为:</p>
<pre>
char自动类型转换为int后的值等于97
char类型和int计算后的值等于66
</pre>
<p><strong>解析：</strong>c1 的值为字符 <strong>a</strong> ,查 ASCII 码表可知对应的 int 类型值为 97， A 对应值为 65，所以 <span class="marked">i2=65+1=66</span>。</p>
<h3>强制类型转换</h3>

<ul><li><p>
1. 条件是转换的数据类型必须是兼容的。</p></li><li><p>
2. 格式：(type)value  type是要强制类型转换后的数据类型
   实例： </p>
<div class="example"> 
<h2 class="example">实例</h2> 
<div class="example_code">
<div class="hl-main"><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-reserved">class</span><span class="hl-code"> </span><span class="hl-identifier">QiangZhiZhuanHuan</span><span class="hl-brackets">{</span><span class="hl-code">
    </span><span class="hl-reserved">public</span><span class="hl-code"> </span><span class="hl-types">static</span><span class="hl-code"> </span><span class="hl-types">void</span><span class="hl-code"> </span><span class="hl-identifier">main</span><span class="hl-brackets">(</span><span class="hl-identifier">String</span><span class="hl-brackets">[</span><span class="hl-brackets">]</span><span class="hl-code"> </span><span class="hl-identifier">args</span><span class="hl-brackets">)</span><span class="hl-brackets">{</span><span class="hl-code">
        </span><span class="hl-types">int</span><span class="hl-code"> </span><span class="hl-identifier">i1</span><span class="hl-code"> = </span><span class="hl-number">123</span><span class="hl-code">;
        </span><span class="hl-types">byte</span><span class="hl-code"> </span><span class="hl-identifier">b</span><span class="hl-code"> = </span><span class="hl-brackets">(</span><span class="hl-types">byte</span><span class="hl-brackets">)</span><span class="hl-identifier">i1</span><span class="hl-code">;</span><span class="hl-comment">//</span><span class="hl-comment">强制类型转换为byte</span><span class="hl-comment"></span><span class="hl-code">
        </span><span class="hl-identifier">System</span><span class="hl-code">.</span><span class="hl-identifier">out</span><span class="hl-code">.</span><span class="hl-identifier">println</span><span class="hl-brackets">(</span><span class="hl-quotes">&quot;</span><span class="hl-string">int强制类型转换为byte后的值等于</span><span class="hl-quotes">&quot;</span><span class="hl-code">+</span><span class="hl-identifier">b</span><span class="hl-brackets">)</span><span class="hl-code">;
    </span><span class="hl-brackets">}</span><span class="hl-code">
</span><span class="hl-brackets">}</span></div>
</div>
</div>
<p>运行结果：</p>
<pre>
int强制类型转换为byte后的值等于123
</pre>
</li></ul>
<h3>隐含强制类型转换</h3>
<ul>
<li><p>
1、 整数的默认类型是 int。</p></li>


<li><p>
2. 小数默认是 double 类型浮点型，在定义 float 类型时必须在数字后面跟上 F 或者 f。
</p></li>
</ul>
<p>
这一节讲解了 Java 的基本数据类型。下一节将探讨不同的变量类型以及它们的用法。</p>			<!-- 其他扩展 -->
						
			</div>
			
		</div>
		
		<div class="previous-next-links">
			<div class="previous-design-link"><i style="font-size:16px;" class="fa fa-arrow-left" aria-hidden="true"></i> <a href="../java/java-object-classes.html" rel="prev"> Java 对象和类</a> </div>
			<div class="next-design-link"><a href="../java/java-variable-types.html" rel="next"> Java 变量类型</a> <i style="font-size:16px;" class="fa fa-arrow-right" aria-hidden="true"></i></div>
		</div>
		<!-- 笔记列表 -->
		<style>
.wrapper {
  /*text-transform: uppercase; */
  background: #ececec;
  color: #555;
  cursor: help;
  font-family: "Gill Sans", Impact, sans-serif;
  font-size: 20px;
  position: relative;
  text-align: center;
  width: 200px;
  -webkit-transform: translateZ(0); /* webkit flicker fix */
  -webkit-font-smoothing: antialiased; /* webkit text rendering fix */
}

.wrapper .tooltip {
  white-space: nowrap;
  font-size: 14px;
  text-align: left;
  background: #96b97d;
  bottom: 100%;
  color: #fff;
  display: block;
  left: -25px;
  margin-bottom: 15px;
  opacity: 0;
  padding: 14px;
  pointer-events: none;
  position: absolute;
  
  -webkit-transform: translateY(10px);
     -moz-transform: translateY(10px);
      -ms-transform: translateY(10px);
       -o-transform: translateY(10px);
          transform: translateY(10px);
  -webkit-transition: all .25s ease-out;
     -moz-transition: all .25s ease-out;
      -ms-transition: all .25s ease-out;
       -o-transition: all .25s ease-out;
          transition: all .25s ease-out;
  -webkit-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
     -moz-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
      -ms-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
       -o-box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
          box-shadow: 2px 2px 6px rgba(0, 0, 0, 0.28);
}
.tooltip a {
	color:#fff;
}
/* This bridges the gap so you can mouse into the tooltip without it disappearing */
.wrapper .tooltip:before {
  bottom: -20px;
  content: " ";
  display: block;
  height: 20px;
  left: 0;
  position: absolute;
  width: 100%;
}  

/* CSS Triangles - see Trevor's post */
.wrapper .tooltip:after {
  border-left: solid transparent 10px;
  border-right: solid transparent 10px;
  border-top: solid #96b97d 10px;
  bottom: -10px;
  content: " ";
  height: 0;
  left: 20%;
  margin-left: -13px;
  position: absolute;
  width: 0;
}
.wrapper .tooltip1 {
	margin-left: 50px;
	padding-top: 0px;
}
/*
.wrapper:hover .tooltip {
  opacity: 1;
  pointer-events: auto;
  -webkit-transform: translateY(0px);
     -moz-transform: translateY(0px);
      -ms-transform: translateY(0px);
       -o-transform: translateY(0px);
          transform: translateY(0px);
}
*/
/* IE can just show/hide with no transition */
.lte8 .wrapper .tooltip {
  display: none;
}

.lte8 .wrapper:hover .tooltip {
  display: block;
}

</style>

<link rel="stylesheet" href="../0/upvotejs.css">
<script src=""></script>
<script src=""></script>
<div class="title" id="comments">
	<h2 class="">
    <div class="altblock">
				<i style="font-size:28px;margin-top: 8px;" class="fa fa-plus-square" aria-hidden="true"></i>
		    </div>
    <span class="mw-headline" id="qa_headline">11  篇笔记</span>
	<span class="mw-headline" id="user_add_note" style="float:right;line-height: 62px;padding-right: 14px;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i>  写笔记</span>
    </h2>
</div>

<div id="postcomments"  style="display:none;" >
	<ol class="commentlist">
		<li class="comment even thread-even depth-1" id="comment-11402"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;大白兔</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;ali***990@foxmail.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://stackoverflow.com/questions/7093186/the-literal-of-int-xxxxx-is-out-of-range">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-11402" data-commid = "11402" class="upvotejs"><a class="upvote"></a> <span class="count">210</span></div></div><div class="comt-main" id="div-comment-11402">Java 里使用 long 类型的数据一定要在数值后面加上 <span class="marked">L</span>，否则将作为整型解析：</p>
<pre>
long g = (long)9223372036854775807;
long h = (long)-9223372036854775808;

或者

long g = 9223372036854775807;
long h = -9223372036854775808;
</pre><p>会出现以下报错信息：</p><pre>
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
The literal 9223372036854775807 of type int is out of range
The literal 9223372036854775808 of type int is out of range 
</pre><p>
溢出了~</p>
<p>解决方法在数值后面加上 <span class="marked">L</span>：</p>
<pre>
long value = 9223372036854775807L;
</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">大白兔</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;大白兔</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;ali***990@foxmail.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://stackoverflow.com/questions/7093186/the-literal-of-int-xxxxx-is-out-of-range">&nbsp;&nbsp;参考地址</a></p></div></span>6年前 (2017-04-26)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-15780"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;LadyLeane</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;q-b***sn.com</p></div><div id="runoobvote-id-15780" data-commid = "15780" class="upvotejs"><a class="upvote"></a> <span class="count">180</span></div></div><div class="comt-main" id="div-comment-15780"><p>引用类型是一个对象类型，它的值是指向内存空间的引用，就是地址，所指向的内存中保存着变量所表示的一个值或一组值。</p>   
<pre>int a;
a = 250; // 声明变量a的同时，系统给a分配了空间。</pre>

<p>引用类型就不是了，只给变量分配了引用空间，数据空间没有分配，因为不知道数据是什么。</p>

<p><strong>错误的例子：</strong></p>

<pre>MyDate today;
today.day = 4; // 发生错误，因为today对象的数据空间未分配。</pre>

<p>引用类型变量在声明后必须通过实例化开辟数据空间，才能对变量所指向的对象进行访问。</p>

<pre>MyDate today;          //将变量分配一个保存引用的空间
today = new MyDate();     // 这句话是2步，首先执行new MyDate（），给today变量开辟数据空间，然后再执行赋值操作</pre>

<p><strong>引用变量赋值：</strong></p>

<pre>MyDate a，b;       // 在内存开辟两个引用空间
a = new MyDate();       // 开辟MyDate对象的数据空间，并把该空间的首地址赋给a
b = a;                   // 将a存储空间中的地址写到b的存储空间中</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">LadyLeane</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;LadyLeane</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;q-b***sn.com</p></div></span>6年前 (2017-08-03)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-16250"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;月汐</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;bul***nitian@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://how2j.cn/k/variable/variable-transfer/264.html">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-16250" data-commid = "16250" class="upvotejs"><a class="upvote"></a> <span class="count">124</span></div></div><div class="comt-main" id="div-comment-16250"><pre>short a = 1;
short b = 2;</pre>
<p><strong>那么 a+b 是什么类型？</strong></p>

<p>答：在java的世界里，如果比int类型小的类型做运算，java在编译的时候就会将它们统一强转成int类型。当是比int类型大的类型做运算，就会自动转换成它们中最大类型那个。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">月汐</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;月汐</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;bul***nitian@163.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="http://how2j.cn/k/variable/variable-transfer/264.html">&nbsp;&nbsp;参考地址</a></p></div></span>6年前 (2017-08-12)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-17121"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;啦啦啦bbb</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;115***8234@qq.com</p></div><div id="runoobvote-id-17121" data-commid = "17121" class="upvotejs"><a class="upvote"></a> <span class="count">102</span></div></div><div class="comt-main" id="div-comment-17121"><p><span class="marked">char a = 'S';</span> char 后面赋值要用单引号，因为是字符型数据类型</p>

<p><span class="marked">String a = "I AM FINE";</span> String 后面赋值要用双引号，因为是字符串数据类型</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">啦啦啦bbb</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;啦啦啦bbb</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;115***8234@qq.com</p></div></span>6年前 (2017-09-03)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-21380"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;CHENG</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;159***3536@qq.com</p></div><div id="runoobvote-id-21380" data-commid = "21380" class="upvotejs"><a class="upvote"></a> <span class="count">126</span></div></div><div class="comt-main" id="div-comment-21380"><h2>数据类型转换的补充
</h2>
<p><strong>1、包装类过渡类型转换</strong></p>

<p>一般情况下，我们首先声明一个变量，然后生成一个对应的包装类，就可以利用包装类的各种方法进行类型转换了。例如：</p>

<p>当希望把float型转换为double型时：</p>

<pre>float f1=100.00f;
Float F1=new Float(f1);
double d1=F1.doubleValue();//F1.doubleValue()为Float类的返回double值型的方法</pre>

<p>简单类型的变量转换为相应的包装类，可以利用包装类的构造函数。即：Boolean(boolean value)、Character(char value)、Integer(int value)、Long(long value)、Float(float value)、Double(double value)</p>

<p>而在各个包装类中，总有形为××Value()的方法，来得到其对应的简单类型数据。利用这种方法，也可以实现不同数值型变量间的转换，例如，对于一个双精度实型类，intValue()可以得到其对应的整型变量，而doubleValue()可以得到其对应的双精度实型变量。</p>

<p><strong>2、字符串与其它类型间的转换</strong></p>

<p>其它类型向字符串的转换</p>
<ul><li>
调用类的串转换方法:X.toString();
</li><li>
自动转换:X+"";
</li><li>
使用String的方法:String.valueOf(X);</li></ul>

<p><strong>3、字符串作为值,向其它类型的转换</strong></p>

<p>1、先转换成相应的封装器实例,再调用对应的方法转换成其它类型</p>

<p>例如，字符中"32.1"转换double型的值的格式为:new Float("32.1").doubleValue()。也可以用:Double.valueOf("32.1").doubleValue()</p>

<p>2、静态parseXXX方法</p>

<pre>String s = "1";
byte b = Byte.parseByte( s );
short t = Short.parseShort( s );
int i = Integer.parseInt( s );
long l = Long.parseLong( s );
Float f = Float.parseFloat( s );
Double d = Double.parseDouble( s );</pre>
<p>3、Character的getNumericValue(char ch)方法</p>

<p><strong>4、Date类与其它数据类型的相互转换</strong></p>

<p>整型和Date类之间并不存在直接的对应关系，只是你可以使用int型为分别表示年、月、日、时、分、秒，这样就在两者之间建立了一个对应关系，在作这种转换时，你可以使用Date类构造函数的三种形式：</p>
<ul><li>
Date(int year, int month, int date)：以int型表示年、月、日
</li><li>
Date(int year, int month, int date, int hrs, int min)：以int型表示年、月、日、时、分
</li><li>
Date(int year, int month, int date, int hrs, int min, int sec)：以int型表示年、月、日、时、分、秒
</li></ul>
<p>在长整型和Date类之间有一个很有趣的对应关系，就是将一个时间表示为距离格林尼治标准时间1970年1月1日0时0分0秒的毫秒数。对于这种对应关系，Date类也有其相应的构造函数：Date(long date)。</p>

<p>获取Date类中的年、月、日、时、分、秒以及星期你可以使用Date类的getYear()、getMonth()、getDate()、getHours()、getMinutes()、getSeconds()、getDay()方法，你也可以将其理解为将Date类转换成int。</p>

<p>而Date类的getTime()方法可以得到我们前面所说的一个时间对应的长整型数，与包装类一样，Date类也有一个toString()方法可以将其转换为String类。</p>

<p>有时我们希望得到Date的特定格式，例如20020324，我们可以使用以下方法，首先在文件开始引入：</p>

<pre>import java.text.SimpleDateFormat;

java.util.Date date = new java.util.Date();
//如果希望得到YYYYMMDD的格式
SimpleDateFormat sy1=new SimpleDateFormat("yyyyMMdd");
String dateFormat=sy1.format(date);
//如果希望分开得到年，月，日
SimpleDateFormat sy=new SimpleDateFormat("yyyy");
SimpleDateFormat sm=new SimpleDateFormat("MM");
SimpleDateFormat sd=new SimpleDateFormat("dd");
String syear=sy.format(date);
String smon=sm.format(date);
String sday=sd.format(date);</pre>

<p><strong>总结：</strong></p>
<p>1、只有 boolean 不参与数据类型的转换</p>

<p>2、自动类型的转换：</p>
<ul><li>
a.常数在表数范围内是能够自动类型转换的
</li><li>
b.数据范围小的能够自动数据类型大的转换（注意特例）
</li><li>
float 到 int，float 到 long，double 到 int，double 到 long 等由浮点类型转换成整数类型时，是不会自动转换的，不然将会丢失精度。
</li><li>
c.引用类型能够自动转换为父类的
</li><li>
d.基本类型和它们包装类型是能够互相转换的
</li></ul>
<p>3、强制类型转换：用圆括号括起来目标类型，置于变量前</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">CHENG</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;CHENG</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;159***3536@qq.com</p></div></span>5年前 (2017-12-08)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-24505"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;程序猿</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;591***987@qq.com</p></div><div id="runoobvote-id-24505" data-commid = "24505" class="upvotejs"><a class="upvote"></a> <span class="count">40</span></div></div><div class="comt-main" id="div-comment-24505"><p>在 java 中，任何字符类型与字符串相加，结果都是拼接。</p>

<pre>String s = null;
s += "hello";
System.out.println(s);  // 输出 nullhello</pre>


<p>原因：先应用 String.valueOf 得出 s 的 value 值，再通过 StringBuilder 拼接 hello，因此将 value 与 hello 进行了拼接。</p>

<pre>String s = null;
s = (new StringBuilder(String.valueOf(s))).append("hello").toString(); 
System.out.println(s);</pre><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">程序猿</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;程序猿</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;591***987@qq.com</p></div></span>5年前 (2018-03-02)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-26967"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;兔2</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yum***126@126.com</p></div><div id="runoobvote-id-26967" data-commid = "26967" class="upvotejs"><a class="upvote"></a> <span class="count">27</span></div></div><div class="comt-main" id="div-comment-26967"><p><strong>包装类 Integer 的自动封装</strong></p>

<pre>Integer a = 1;</pre>
<p>int 类型在赋值到 Integer 类时，会自动封装，调用 Integer 的 valueOf(int i) 方法。</p>

<pre>Integer a = Integer.valueOf(1);</pre>

<pre>/**
 * Returns an {@code Integer} instance representing the specified
 * {@code int} value.  If a new {@code Integer} instance is not
 * required, this method should generally be used in preference to
 * the constructor {@link #Integer(int)}, as this method is likely
 * to yield significantly better space and time performance by
 * caching frequently requested values.
 *
 * This method will always cache values in the range -128 to 127,
 * inclusive, and may cache other values outside of this range.
 *
 * @param  i an {@code int} value.
 * @return an {@code Integer} instance representing {@code i}.
 * @since  1.5
 */
public static Integer valueOf(int i) {
    assert IntegerCache.high &gt;= 127;
    if (i &gt;= IntegerCache.low &amp;&amp; i &lt;= IntegerCache.high)
        return IntegerCache.cache[i + (-IntegerCache.low)];
    return new Integer(i);
}</pre>
<p>当 i &gt;= -128 && i &lt;= 127 时，Integer.valueOf(i) 会将 i 存储在内部类 IntegerCache的static final Integer cache[]里，这一字节的缓存内存地址是静态的，返回值即:</p>

<pre>IntegerCache.cache[i + (-IntegerCache.low)]</pre>

<p>因此:</p>
<pre>Integer a = 1; 
Integer b = 1;</pre> 
<p>a 和 b 的引用都指向同一个对象，即 <strong>a == b</strong>。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">兔2</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;兔2</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;yum***126@126.com</p></div></span>5年前 (2018-05-05)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-37966"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;flaming</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;248***1347@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://blog.csdn.net/login_sonata/article/details/71001851">&nbsp;&nbsp;参考地址</a></p></div><div id="runoobvote-id-37966" data-commid = "37966" class="upvotejs"><a class="upvote"></a> <span class="count">40</span></div></div><div class="comt-main" id="div-comment-37966"><p>原始类型：<span class="marked">boolean，char，byte，short，int，long，float，double</span>。</p>

<p>包装类型：<span class="marked">Boolean，Character，Byte，Short，Integer，Long，Float，Double</span>。</p>

<p>Java 中的基本数据类型只有以上 8 个，除了基本类型（primitive type），剩下的都是引用类型（reference type）。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">flaming</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;flaming</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;248***1347@qq.com</p><p><i class="fa fa-external-link" aria-hidden="true"></i> <a rel="nofollow" target="_blank" href="https://blog.csdn.net/login_sonata/article/details/71001851">&nbsp;&nbsp;参考地址</a></p></div></span>4年前 (2018-12-12)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-52676"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;路人</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;758***817@qq.com</p></div><div id="runoobvote-id-52676" data-commid = "52676" class="upvotejs"><a class="upvote"></a> <span class="count">15</span></div></div><div class="comt-main" id="div-comment-52676"><p>byte 数据类型是8位、有符号的，以二进制补码表示的整数；</p><p>short 数据类型是 16 位、有符号的以二进制补码表示的整数</p><p>int 数据类型是32位、有符号的以二进制补码表示的整数；</p><p>long 数据类型是 64 位、有符号的以二进制补码表示的整数；</p><p>float 数据类型是单精度、32位、符合IEEE 754标准的浮点数；</p><p>double 数据类型是双精度、64 位、符合IEEE 754标准的浮点数；</p><p>boolean数据类型表示一位的信息；</p><p>char类型是一个单一的 16 位 Unicode 字符；</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">路人</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;路人</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;758***817@qq.com</p></div></span>3年前 (2020-04-14)</div></div></li><!-- #comment-## -->
<li class="comment odd alt thread-odd thread-alt depth-1" id="comment-63562"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;嬴斯</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;207***3769@qq.com</p></div><div id="runoobvote-id-63562" data-commid = "63562" class="upvotejs"><a class="upvote"></a> <span class="count">16</span></div></div><div class="comt-main" id="div-comment-63562"><p>回复 <span class="marked"><a href="#comment-11402" rel="nofollow ugc">@大白兔</a></span> 所提出的问题，java默认有小数部分的数为double类型，所以要将一个有小数部分的常量赋值给float类型的变量时，需要在常量后方写上“f”、“F”，系统才将之认为是一个float类型的值。</p><p>但在使用整型类型long时，何时写“l”或者“L”，判断依据在于输入的常量值是否大于int类型的存储极限，如果大于int类型的存储极限则需要写尾缀。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">嬴斯</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;嬴斯</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;207***3769@qq.com</p></div></span>2年前 (2021-05-07)</div></div></li><!-- #comment-## -->
<li class="comment even thread-even depth-1" id="comment-72726"><span class="comt-f">#0</span><div class="comt-avatar wrapper"><i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i><div class="tooltip"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;乐嘻嘻</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;bri***q.com</p></div><div id="runoobvote-id-72726" data-commid = "72726" class="upvotejs"><a class="upvote"></a> <span class="count">6</span></div></div><div class="comt-main" id="div-comment-72726"><p>回复 <a href="#comment-21380" rel="nofollow ugc"><span class="marked">@CHENG</span></a> 的Character的getNumericValue(char ch)方法，在文档中是这样指定的</p><p>返回指定的 Unicode 字符表示的 <code>int</code> 值</p><p>字母 A-Z 的大写（<code>'\u0041'</code> 到 <code>'\u005A'</code>）、小写（<code>'\u0061'</code> 到 <code>'\u007A'</code>）和全形参数（<code>'\uFF21'</code> 到 <code>'\uFF3A'</code> 和 <code>'\uFF41'</code> 到 <code>'\uFF5A'</code>）形式拥有从 10 到 35 的数值。这独立于 Unicode 规范，该规范没有为这些 <code>char</code> 值分配数值。&nbsp;</p><p>可以当做36进制，1-9_A-Z里 A=10 Z=25，可以比较方便取得字母对应的数值。</p><p>如果字符中没有数值，则返回 -1。如果字符中有一个数值，但无法将它表示为非负整数（例如，小数值），则返回 -2。</p><div class="comt-meta wrapper"><span class="comt-author"><a target="_blank" href="javascript:;">乐嘻嘻</a><div class="tooltip tooltip1"><p><i class="fa fa-user" aria-hidden="true"></i>&nbsp;&nbsp;&nbsp;乐嘻嘻</p><p><i class="fa fa-envelope" aria-hidden="true"></i>&nbsp;&nbsp;bri***q.com</p></div></span>11个月前 (05-19)</div></div></li><!-- #comment-## -->
	</ol>
	<div class="pagenav">
			</div>
</div>
<div id="respond" class="no_webshot"> 
		<div class="comment-signarea" style="display:none; padding: 20px 20px;"> 
	<h3 class="text-muted" id="share_code" style="color: #799961;"><i class="fa fa-pencil-square-o" aria-hidden="true"></i> 点我分享笔记</h3>
	<!--
	<p style="font-size:14px;">笔记需要是本篇文章的内容扩展！</p><br>
	<p style="font-size:12px;"><a href="../tougao" target="_blank">文章投稿，可点击这里</a></p>
	<p style="font-size:14px;"><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>
		<h3 class="text-muted"><i class="fa fa-info-circle" aria-hidden="true"></i> 分享笔记前必须<a href="javascript:;" class="runoob-pop">登录</a>！</h3>
		<p><a href="../w3cnote/runoob-user-test-intro.html#invite" target="_blank">注册邀请码获取方式</a></p>-->
	</div>
		
	<form action="/wp-content/themes/runoob/option/addnote.php" method="post" id="commentform" style="display:none;">
		<div class="comt">
			<div class="comt-title">
				<i style="font-size:36px;" class="fa fa-user-circle" aria-hidden="true"></i>				<p><a id="cancel-comment-reply-link" href="javascript:;">取消</a></p>
			</div>
			<div class="comt-box">
			<div id="mded"></div>
			
				<div class="comt-ctrl">
					<div class="comt-tips"><input type='hidden' name='comment_post_ID' value='4986' id='comment_post_ID' />
<input type='hidden' name='comment_parent' id='comment_parent' value='0' />
</div>
					<button type="submit" name="submit" id="submit" tabindex="5"><i class="fa fa-pencil" aria-hidden="true"></i> 分享笔记</button>
				</div>
			</div>
		
				
					<div class="comt-comterinfo"> 
						<ul id="comment-author-info">
							<li class="form-inline"><label class="hide" for="author">昵称</label><input class="ipt" type="text" name="author" id="author" value="" tabindex="2" placeholder="昵称"><span class="text-muted">昵称 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="email">邮箱</label><input class="ipt" type="text" name="email" id="email" value="" tabindex="3" placeholder="邮箱"><span class="text-muted">邮箱 (必填)</span></li>
							<li class="form-inline"><label class="hide" for="url">引用地址</label><input class="ipt" type="text" name="url" id="url" value="" tabindex="4" placeholder="引用地址"><span class="text-muted">引用地址</span></li>
						</ul>
					</div>
				
			
		</div>

	</form>
	</div>
<script type="text/javascript">
$(function() {
	//初始化编辑器
	
	var editor = new Simditor({
	  textarea: $('#mded'),
	  placeholder: '写笔记...',
	  upload:false,
	 // upload: {url:'/api/comment_upload_file.php',params: null,fileKey: 'upload_file',connectionCount: 1,leaveConfirm: '文件正在上传，您确定离开?'},
	  defaultImage: 'https://www.runoob.com/images/logo.png',
	  codeLanguages: '',
	  autosave: 'editor-content',
	  toolbar: [  'bold','code','ul','ol','image' ]
	});
	editor.on('selectionchanged', function() {
		$(".code-popover").hide();
	});

	// 提交数据
	$("#share_code").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		
	});
	$("#user_add_note").click(function() {
		$(".comment-signarea").hide();
		$("#commentform").show();
		$('html, body').animate({
       	    scrollTop: $("#respond").offset().top
    	}, 200);
	});

	// 提交笔记
	var commentform=$('#commentform');
	commentform.prepend('<div id="comment-status" style="display:none;" ></div>');
	var statusdiv=$('#comment-status');
	
	commentform.submit(function(e){
		e.preventDefault();
		var noteContent = editor.getValue();
		// console.log(noteContent);
		noteContent = noteContent.replace(/<pre><code>/g,"<pre>");
		noteContent = noteContent.replace(/<\/code><\/pre>/g,"</pre>");
		
		// 系列化表单数据
		var comment_parent = 0;
		var is_user_logged_in = $("#is_user_logged_in").val();
		var comment_post_ID =  4986;
		var _wp_unfiltered_html_comment = $("#_wp_unfiltered_html_comment").val();
		var comment = noteContent;
		var author = $("#author").val();
		var url = $("#url").val();
		var email = $("#email").val();
		if(isBlank(author) && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入昵称！</p>').show();
		} else if(isBlank(email)  && is_user_logged_in==0) {
			statusdiv.html('<p  class="ajax-error">请输入邮箱！</p>').show();
		} else {
			// var formdata=commentform.serialize() + "&comment=" + noteContent ;
			// 添加状态信息
			statusdiv.html('<p>Processing...</p>').show();
			// 获取表单提交地址
			var formurl=commentform.attr('action');
			
			// 异步提交
			$.ajax({
					type: 'post',
					url: formurl,
					dataType:'json',
					data: {"comment_parent":comment_parent,"comment_post_ID":comment_post_ID, "_wp_unfiltered_html_comment":_wp_unfiltered_html_comment,"comment":comment,"url":url, "email":email,"author":author},
					error: function(XMLHttpRequest, textStatus, errorThrown){
					statusdiv.html('<p class="ajax-error" >数据不完整或表单提交太快了！</p>').show();
				},
				success: function(data, textStatus){
					if(data.errorno=="0") {
						$("#submit").prop('disabled', true);
						statusdiv.html('<p class="ajax-success" >笔记已提交审核，感谢分享笔记！</p>').show();
						alert('笔记已提交审核，感谢分享笔记！');
					}else{
						statusdiv.html('<p class="ajax-error" >'+data.msg+'</p>').show();
					}
					commentform.find('textarea[name=comment]').val('');
				}
			});
			setTimeout(function(){
		        $("#submit").prop('disabled', false);
		    }, 10*1000);
		}
		return false;

	});
	$(".comt-author").click(function() {
		href = $(this).children("a").attr("href");
		if(href.indexOf("/note/")!=-1) {
			var win = window.open(href, '_blank');
  			win.focus();
		}
	});
	$(".comt-meta span").hover(function(){
		$(this).children(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).children(".tooltip").removeAttr("style");
	});
	/*
	$(".wrapper i").hover(function(){
		$(this).siblings(".tooltip").css({ "opacity": 1, "pointer-events": "auto"});
	},function(){
		$(this).siblings(".tooltip").css({ "opacity": 0, "pointer-events": "auto"});
	});
	*/
	//Upvote.create('runoobvote-id', {callback: vote_callback});
	var ajaxurl = 'https://www.runoob.com/wp-admin/admin-ajax.php';
	var callback = function(data) {
		//console.log($('#runoobvote-id').upvote('upvoted'));
		//console.log($('#runoobvote-id').upvote('downvoted'));
		//console.log(data);
		_vote_action = data.action;
		id_arr = data.id.split('-');
		um_id= id_arr[2];
		//console.log(um_id);
		
		var re = /^[1-9]+/;
		if (re.test(um_id)) { 
			var ajax_data = {
				_vote_action: _vote_action,
				action: "pinglun_zan",
				um_id: um_id,
				um_action: "ding"
			};
			//console.log(ajax_data);
			$.post(ajaxurl,ajax_data,function(status){
				//if(status.vote_num>999) {
				//	_voteHtml = '<span style="display: block; text-align: center;font-size: 20px; color: #6a737c; margin: 8px 0;">'+kFormatter(status.vote_num) +'</span>';
				//	$("#runoobvote-id-" + um_id + " .count").hide().after(_voteHtml);
				//}
				
			});
		}
	};
	if($('#comments').length && $('.upvotejs').length){
		$('.upvotejs').upvote({id: 4986, callback: callback});
	
		$.post(ajaxurl,{"action":"pinglun_zan","postid":4986},function(data){  
			$(data).each(function(key,value) {
				$("#runoobvote-id-" + value.commid + " .upvote").addClass(value.upvotejs_class);
				$("#runoobvote-id-" + value.commid + " .downvote").addClass(value.downvote_class);
				$("#runoobvote-id-" + value.commid + " .count").text(value.upvote_count);
			})
		},'json');
		
	}
	
	
});
function isBlank(str) {
    return (!str || /^\s*$/.test(str));
}
function kFormatter(num) {
	// return num;
    return Math.abs(num) > 999 ? Math.sign(num)*((Math.abs(num)/1000).toFixed(1)) + 'k' : Math.sign(num)*Math.abs(num)
}

</script>

<link rel="stylesheet" href="../0/qa.css?1.44">
<link rel="stylesheet" type="text/css" href="../0/simditor.min.css" />
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
<script type="text/javascript" src=""></script>
		<div class="sidebar-box ">
				

<style>	
.responsive_ad1 { display:none; }
@media(min-width: 800px) { .responsive_ad1 {  display:block;margin:0 auto;} }
</style>
<div id="ad-336280" >

<script async src=""
     crossorigin="anonymous"></script>
<!-- 移动版 自动调整 -->
<ins class="adsbygoogle"
     style="display:block"
     data-ad-client="ca-pub-5751451760833794"
     data-ad-slot="1691338467"
     data-ad-format="auto"
     data-full-width-responsive="true"></ins>
<script>
     (adsbygoogle = window.adsbygoogle || []).push({});
</script>
		</div>
				</div>
		
	</div>
</div>
	

<!-- 右边栏 -->
<div class="fivecol last right-column">

<style>
.sidebar-tree .double-li {
    width:300px;
}
.sidebar-tree .double-li li {
    width: 44%;
    line-height: 1.5em;
    border-bottom: 1px solid #ccc;
    float: left;
    display: inline;
}
</style>

    
        <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here" style="margin: 0 auto;">
            <a href="javascript:void(0);" style="font-size: 16px; color:#64854c;font-weight:bold;"> <i class="fa fa-list" aria-hidden="true"></i> 分类导航</a>
        </div>
    <div class="sidebar-box sidebar-cate">
        
        <div class="sidebar-tree" >
            <ul><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> HTML / CSS</a><ul class="double-li"><li><a title="HTML 教程" href="../html/html-tutorial.html">HTML 教程</a></li><li><a title="HTML5 教程" href="../html/html5-intro.html">HTML5 教程</a></li><li><a title="CSS 教程" href="../css/css-tutorial.html">CSS 教程</a></li><li><a title="CSS3 教程" href="../css3/css3-tutorial.html">CSS3 教程</a></li><li><a title="Bootstrap3 教程" href="../bootstrap/bootstrap-tutorial.html">Bootstrap3 教程</a></li><li><a title="Bootstrap4 教程" href="../bootstrap4/bootstrap4-tutorial.html">Bootstrap4 教程</a></li><li><a title="Bootstrap5 教程" href="../bootstrap5/bootstrap5-tutorial.html">Bootstrap5 教程</a></li><li><a title="Font Awesome 教程" href="../font-awesome/fontawesome-tutorial.html">Font Awesome 教程</a></li><li><a title="Foundation 教程" href="../foundation/foundation-tutorial.html">Foundation 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> JavaScript</a><ul class="double-li"><li><a title="JavaScript 教程" href="../js/js-tutorial.html">JavaScript 教程</a></li><li><a title="HTML DOM 教程" href="../htmldom/htmldom-tutorial.html">HTML DOM 教程</a></li><li><a title="jQuery 教程" href="../jquery/jquery-tutorial.html">jQuery 教程</a></li><li><a title="AngularJS 教程" href="../angularjs/angularjs-tutorial.html">AngularJS 教程</a></li><li><a title="AngularJS2 教程" href="../angularjs2/angularjs2-tutorial.html">AngularJS2 教程</a></li><li><a title="Vue.js 教程" href="../vue2/vue-tutorial.html">Vue.js 教程</a></li><li><a title="Vue3 教程" href="../vue3/vue3-tutorial.html">Vue3 教程</a></li><li><a title="React 教程" href="../react/react-tutorial.html">React 教程</a></li><li><a title="TypeScript 教程" href="../typescript/ts-tutorial.html">TypeScript 教程</a></li><li><a title="jQuery UI 教程" href="../jqueryui/jqueryui-tutorial.html">jQuery UI 教程</a></li><li><a title="jQuery EasyUI 教程" href="../jeasyui/jqueryeasyui-tutorial.html">jQuery EasyUI 教程</a></li><li><a title="Node.js 教程" href="../nodejs/nodejs-tutorial.html">Node.js 教程</a></li><li><a title="AJAX 教程" href="../ajax/ajax-tutorial.html">AJAX 教程</a></li><li><a title="JSON 教程" href="../json/json-tutorial.html">JSON 教程</a></li><li><a title="Echarts 教程" href="../echarts/echarts-tutorial.html">Echarts 教程</a></li><li><a title="Chart.js 教程" href="../chartjs/chartjs-tutorial.html">Chart.js 教程</a></li><li><a title="Highcharts 教程" href="../highcharts/highcharts-tutorial.html">Highcharts 教程</a></li><li><a title="Google 地图 教程" href="../googleapi/google-maps-basic.html">Google 地图 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 服务端</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="Python2.x 教程" href="../python/python-tutorial.html">Python2.x 教程</a></li><li><a title="Linux 教程" href="../linux/linux-tutorial.html">Linux 教程</a></li><li><a title="Docker 教程" href="../docker/docker-tutorial.html">Docker 教程</a></li><li><a title="Ruby 教程" href="../ruby/ruby-tutorial.html">Ruby 教程</a></li><li><a title="Java 教程" href="../java/java-tutorial.html">Java 教程</a></li><li><a title="C 教程" href="../c/c-tutorial.html">C 教程</a></li><li><a title="C++ 教程" href="../cplusplus/cpp-tutorial.html">C++ 教程</a></li><li><a title="Perl 教程" href="../perl/perl-tutorial.html">Perl 教程</a></li><li><a title="Servlet 教程" href="../servlet/servlet-tutorial.html">Servlet 教程</a></li><li><a title="JSP 教程" href="../jsp/jsp-tutorial.html">JSP 教程</a></li><li><a title="Lua 教程" href="../lua/lua-tutorial.html">Lua 教程</a></li><li><a title="Rust 教程" href="../rust/rust-tutorial.html">Rust 教程</a></li><li><a title="Scala 教程" href="../scala/scala-tutorial.html">Scala 教程</a></li><li><a title="Go 教程" href="../go/go-tutorial.html">Go 教程</a></li><li><a title="PHP 教程" href="../php/php-tutorial.html">PHP 教程</a></li><li><a title="数据结构与算法" href="../data-structures/data-structures-tutorial.html">数据结构与算法</a></li><li><a title="Django 教程" href="../django/django-tutorial.html">Django 教程</a></li><li><a title="Zookeeper 教程" href="../w3cnote/zookeeper-tutorial.html">Zookeeper 教程</a></li><li><a title="设计模式" href="../design-pattern/design-pattern-tutorial.html">设计模式</a></li><li><a title="正则表达式" href="../regexp/regexp-tutorial.html">正则表达式</a></li><li><a title="Maven 教程" href="../maven/maven-tutorial.html">Maven 教程</a></li><li><a title="Verilog 教程" href="../w3cnote/verilog-tutorial.html">Verilog 教程</a></li><li><a title="ASP 教程" href="../asp/asp-tutorial.html">ASP 教程</a></li><li><a title="AppML 教程" href="../appml/appml-tutorial.html">AppML 教程</a></li><li><a title="VBScript 教程" href="../vbscript/vbscript-tutorial.html">VBScript 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据库</a><ul class="double-li"><li><a title="SQL 教程" href="../sql/sql-tutorial.html">SQL 教程</a></li><li><a title="MySQL 教程" href="../mysql/mysql-tutorial.html">MySQL 教程</a></li><li><a title="PostgreSQL 教程" href="../postgresql/postgresql-tutorial.html">PostgreSQL 教程</a></li><li><a title="SQLite 教程" href="../sqlite/sqlite-tutorial.html">SQLite 教程</a></li><li><a title="MongoDB 教程" href="../mongodb/mongodb-tutorial.html">MongoDB 教程</a></li><li><a title="Redis 教程" href="../redis/redis-tutorial.html">Redis 教程</a></li><li><a title="Memcached 教程" href="../Memcached/Memcached-tutorial.html">Memcached 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 数据分析</a><ul class="double-li"><li><a title="Python 教程" href="../python3/python3-tutorial.html">Python 教程</a></li><li><a title="NumPy 教程" href="../numpy/numpy-tutorial.html">NumPy 教程</a></li><li><a title="Pandas 教程" href="../pandas/pandas-tutorial.html">Pandas 教程</a></li><li><a title="Matplotlib 教程" href="../matplotlib/matplotlib-tutorial.html">Matplotlib 教程</a></li><li><a title="Scipy 教程" href="../scipy/scipy-tutorial.html">Scipy 教程</a></li><li><a title="R 教程" href="../r/r-tutorial.html">R 教程</a></li><li><a title="Julia 教程" href="../julia/julia-tutorial.html">Julia 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 移动端</a><ul class="double-li"><li><a title="Android 教程" href="../w3cnote/android-tutorial-intro.html">Android 教程</a></li><li><a title="Swift 教程" href="../swift/swift-tutorial.html">Swift 教程</a></li><li><a title="jQuery Mobile 教程" href="../jquerymobile/jquerymobile-tutorial.html">jQuery Mobile 教程</a></li><li><a title="ionic 教程" href="../ionic/ionic-tutorial.html">ionic 教程</a></li><li><a title="Kotlin 教程" href="../kotlin/kotlin-tutorial.html">Kotlin 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> XML 教程</a><ul class="double-li"><li><a title="XML 教程" href="../xml/xml-tutorial.html">XML 教程</a></li><li><a title="DTD 教程" href="../dtd/dtd-tutorial.html">DTD 教程</a></li><li><a title="XML DOM 教程" href="../dom/dom-tutorial.html">XML DOM 教程</a></li><li><a title="XSLT 教程" href="../xsl/xsl-tutorial.html">XSLT 教程</a></li><li><a title="XPath 教程" href="../xpath/xpath-tutorial.html">XPath 教程</a></li><li><a title="XQuery 教程" href="../xquery/xquery-tutorial.html">XQuery 教程</a></li><li><a title="XLink 教程" href="../xlink/xlink-tutorial.html">XLink 教程</a></li><li><a title="XPointer 教程" href="../xlink/xlink-tutorial.html">XPointer 教程</a></li><li><a title="XML Schema 教程" href="../schema/schema-tutorial.html">XML Schema 教程</a></li><li><a title="XSL-FO 教程" href="../xslfo/xslfo-tutorial.html">XSL-FO 教程</a></li><li><a title="SVG 教程" href="../svg/svg-tutorial.html">SVG 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> ASP.NET</a><ul class="double-li"><li><a title="ASP.NET 教程" href="../aspnet/aspnet-tutorial.html">ASP.NET 教程</a></li><li><a title="C# 教程" href="../csharp/csharp-tutorial.html">C# 教程</a></li><li><a title="Web Pages 教程" href="../aspnet/webpages-intro.html">Web Pages 教程</a></li><li><a title="Razor 教程" href="../aspnet/razor-intro.html">Razor 教程</a></li><li><a title="MVC 教程" href="../aspnet/mvc-intro.html">MVC 教程</a></li><li><a title="Web Forms 教程" href="../aspnet/aspnet-intro.html">Web Forms 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> Web Service</a><ul class="double-li"><li><a title="Web Service 教程" href="../webservices/webservices-tutorial.html">Web Service 教程</a></li><li><a title="WSDL 教程" href="../wsdl/wsdl-tutorial.html">WSDL 教程</a></li><li><a title="SOAP 教程" href="../soap/soap-tutorial.html">SOAP 教程</a></li><li><a title="RSS 教程" href="../rss/rss-tutorial.html">RSS 教程</a></li><li><a title="RDF 教程" href="../rdf/rdf-tutorial.html">RDF 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 开发工具</a><ul class="double-li"><li><a title="Eclipse 教程" href="../eclipse/eclipse-tutorial.html">Eclipse 教程</a></li><li><a title="Git 教程" href="../git/git-tutorial.html">Git 教程</a></li><li><a title="Svn 教程" href="../svn/svn-tutorial.html">Svn 教程</a></li><li><a title="Markdown 教程" href="../markdown/md-tutorial.html">Markdown 教程</a></li></ul></li><li style="margin: 0;"><a href="javascript:void(0);" class="tit"> 网站建设</a><ul class="double-li"><li><a title="HTTP 教程" href="../http/http-tutorial.html">HTTP 教程</a></li><li><a title="网站建设指南" href="../web/web-buildingprimer.html">网站建设指南</a></li><li><a title="浏览器信息" href="../browsers/browser-information.html">浏览器信息</a></li><li><a title="网站主机教程" href="../hosting/hosting-tutorial.html">网站主机教程</a></li><li><a title="TCP/IP 教程" href="../tcpip/tcpip-tutorial.html">TCP/IP 教程</a></li><li><a title="W3C 教程" href="../w3c/w3c-tutorial.html">W3C 教程</a></li><li><a title="网站品质" href="../quality/quality-tutorial.html">网站品质</a></li></ul></li></ul>            </div>
    
    </div>
    </div>
    <br>
    
    <div class="sidebar-box re-box re-box-large">
        <div class="sidebar-box recommend-here">
            <a href="javascript:void(0);">Advertisement</a>
        </div>
        <div class="re-600160" id="sidebar-right-re">
                <script async src=""></script>
        <!-- 侧栏1 -->
        <ins class="adsbygoogle"
             style="display:inline-block;width:160px;height:600px"
             data-ad-client="ca-pub-5751451760833794"
             data-ad-slot="4106274865"></ins>
        <script>
        (adsbygoogle = window.adsbygoogle || []).push({});
        </script>
                </div>
    </div>
</div></div>

</div>

<script>
var aid = 4986;
function coll() {
	$.post( '/wp-content/themes/runoob/option/user/userinfo.php', {aid:aid, action:"collarticle", opt:'add'},function( data ) {
		if(data.error==0) {
			$("#content").find("h1:first").find("a").attr("href","javascript:void(0);");
			$("#content").find("h1:first").find("img").attr("src","http://www.runoob.com/wp-content/themes/runoob/assets/img/coll2.png").css({width:32+"px",height:32+"px"});
		}
		alert(data.msg);
	},'json');
}
</script>


<!-- 反馈对话框开始 -->
<script src=""></script>
<link rel="stylesheet" href="../0/feedback.css?1.0" />
<script type="text/javascript">
$.feedback({
    ajaxURL: '/feedback/runoob_feedback.php',
	html2canvasURL: '/wp-content/themes/runoob/assets/feedback/stable/2.0/html2canvas.js',
	onClose: function () {
         window.location.reload();
    }
});
</script>
<!-- 反馈对话框结束 -->
<button class="feedback-btn feedback-btn-gray">反馈/建议</button>
<!-- 底部 -->
<div id="footer" class="mar-t50">
   <div class="runoob-block">
    <div class="runoob cf">
     <dl>
      <dt>
       在线实例
      </dt>
      <dd>
       &middot;<a target="_blank" href="../html/html-examples.html">HTML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../css/css-examples.html">CSS 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../js/js-examples.html">JavaScript 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../ajx/ajax-examples.html">Ajax 实例</a>
      </dd>
       <dd>
       &middot;<a target="_blank" href="../jquery/jquery-examples.html">jQuery 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../xml/xml-examples.html">XML 实例</a>
      </dd>
      <dd>
       &middot;<a target="_blank" href="../java/java-examples.html">Java 实例</a>
      </dd>
     
     </dl>
     <dl>
      <dt>
      字符集&工具
      </dt>
      <dd>
       &middot; <a target="_blank" href="../charsets/html-charsets.html">HTML 字符集设置</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-ascii.html">HTML ASCII 字符集</a>
      </dd>
     <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6939/">JS 混淆/加密</a>
      </dd> 
      <dd>
       &middot; <a target="_blank" href="https://c.runoob.com/front-end/6232/">PNG/JPEG 图片压缩</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="../tags/html-colorpicker.html">HTML 拾色器</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/53">JSON 格式化工具</a>
      </dd>
      <dd>
       &middot; <a target="_blank" href="..//c.runoob.com/front-end/6680/">随机数生成器</a>
      </dd>
     </dl>
     <dl>
      <dt>
       最新更新
      </dt>
                   <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imread.html" title="Matplotlib imread() 方法">Matplotlib imre...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imsave.html" title="Matplotlib imsave() 方法">Matplotlib imsa...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-imshow.html" title="Matplotlib imshow() 方法">Matplotlib imsh...</a>
      </dd>
              <dd>
       &middot;
      <a href="../matplotlib/matplotlib-hist.html" title="Matplotlib 直方图">Matplotlib 直方图</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-func-object.html" title="Python object() 函数">Python object()...</a>
      </dd>
              <dd>
       &middot;
      <a href="../python3/python-ai-draw.html" title="Python AI 绘画">Python AI 绘画</a>
      </dd>
              <dd>
       &middot;
      <a href="../w3cnote/cursor-editor.html" title="神辅助 Cursor 编辑器，加入 GPT-4 让编码更轻松！">神辅助 Cursor ...</a>
      </dd>
             </dl>
     <dl>
      <dt>
       站点信息
      </dt>
      <dd>
       &middot;
       <a target="_blank" href="mailto:admin@runoob.com" rel="external nofollow">意见反馈</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../disclaimer">免责声明</a>
       </dd>
      <dd>
       &middot;
       <a target="_blank" href="../aboutus">关于我们</a>
       </dd>
      <dd>
       &middot;
      <a target="_blank" href="../archives">文章归档</a>
      </dd>
    
     </dl>
    
     <div class="search-share">
      <div class="app-download">
        <div>
         <strong>关注微信</strong>
        </div>
      </div>
      <div class="share">
      <img width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png" />
       </div>
     </div>
     
    </div>
   </div>
   <div class="w-1000 copyright">
     Copyright &copy; 2013-2023    <strong><a href="../" target="_blank">菜鸟教程</a></strong>&nbsp;
    <strong><a href="../" target="_blank">runoob.com</a></strong> All Rights Reserved. 备案号：<a target="_blank" rel="nofollow" href="https://beian.miit.gov.cn/">闽ICP备15012807号-1</a>
   </div>
  </div>
  <div class="fixed-btn">
    <a class="go-top" href="javascript:void(0)" title="返回顶部"> <i class="fa fa-angle-up"></i></a>
    <a class="qrcode"  href="javascript:void(0)" title="关注我们"><i class="fa fa-qrcode"></i></a>
    <a class="writer" style="display:none" href="javascript:void(0)"   title="标记/收藏"><i class="fa fa-star" aria-hidden="true"></i></a>
    <!-- qrcode modal -->
    <div id="bottom-qrcode" class="modal panel-modal hide fade in">
      <h4>微信关注</h4>
      <div class="panel-body"><img alt="微信关注" width="128" height="128" src="/wp-content/themes/runoob/assets/images/qrcode.png"></div> 
    </div>
  </div>

 <div style="display:none;">
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-84264393-2"></script>
<script>
  window.dataLayer = window.dataLayer || [];
  function gtag(){dataLayer.push(arguments);}
  gtag('js', new Date());

  gtag('config', 'UA-84264393-2');
</script>
<script>
var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?3eec0b7da6548cf07db3bc477ea905ee";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();
</script>

</div>
<script>
window.jsui={
    www: 'https://www.runoob.com',
    uri: 'https://www.runoob.com/wp-content/themes/runoob'
};
</script>

<script src=""></script>
<script src=""></script>

</body>
</html>